<template>
	<image @click="hanldeCollect" class="navber-right"
		:src="isCollect == 1 ? '../../static/icon/has-like.png':'../../static/icon/no-like.png' " mode="">
	</image>
</template>

<script>
	// 接口地址
	import {
		focusGoods,
		focusedGoods
	} from '@/config/api.js'
	export default {
		name: "isCollect",
		props: {
			goodsId: {
				type: String | Number,
				default: 0
			}
		},
		data() {
			return {
				isCollect: 2
			};
		},
		watch: {
			goodsId(newVal, oldVal) {
				this.getCollect();
			}
		},
		methods: {
			// 获取收藏
			getCollect() {
				focusedGoods({
					// goods_id: this.goodsId,
					ret: 'goods_id',
				}).then(res => {
					let status = res.data.lists.includes(this.goodsId) ? 1 : 2
					this.isCollect = status;
				})
			},
			// 点击收藏
			hanldeCollect() {
				this.isCollect = this.isCollect == 1 ? 2 : 1;
				focusGoods({
					goods_id: this.goodsId,
					status: this.isCollect
				}).then(res => {
					uni.$u.toast(res.msg);
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.navber-right {
		width: 48rpx;
		height: 48rpx;
	}
</style>